<?php
include './inc/SESSION.php';
include './inc/DB.php';
include './inc/TOOLBOX.php';
include './inc/XHTML.php';
include './inc/DEFINE.php';

/**
 * PAGE Class - Collects all page elements into one
 */
class PAGE {
    private $session;
    private $tools;
    private $db;
    private $xhtml;

    /**
     * Descriptor for page - initializes session, tools, db and xhtml
     * @param string $title
     */
    function PAGE($title,$menu="") {
        $this->session = new SESSION();
        $this->tools = new TOOLBOX();
        $this->db = new DB(DBURL, DBUSER, DBPASS, DBNAME);
        if(strlen($title)>0) {
            $this->xhtml = new XHTML(TITLE.$title,$menu);

            if($this->s()->getvar("loginOk")=="1") {
                $printuser ="<div align=\"right\"><font align=\"right\" style=\"font-size: x-small;\">".
                        $this->s()->getvar("name").
                        " (".$this->s()->getvar("username").
                        ", <b>".
                        $this->s()->getvar("type").
                        "</b>) - <a href=\"logout.php\">[Έξοδος]</a></font></div>\n";
                echo $printuser;
            }
        }
    }


    /**
     * Returns PAGE's session class
     * @return SESSION
     */
    function s() {
        return

                $this->
                session;
    }

    /**
     * Returns PAGE's toolbox class
     * @return TOOLBOX
     */
    function t() {
        return

                $this->
                tools;
    }

    /**
     * Returns PAGE's db class
     * @return DB
     */
    function db() {
        return

                $this->
                db;
    }


    /**
     * Returns PAGE's db class
     * @return DB
     */
    function x() {
        return

                $this->
                xhtml;
    }

    /**
     * Closes db connection and prints footer on xhtml
     */
    function close() {


        $this->db->close();
        $this->xhtml->footer();
    }
}
?>
